<template>
  <view class="ticket-detail-page">
    <view class="wrap">
      <view class="ticket-list">
        <view class="ticket-item">
          <view class="ticket-title">
            <view class="title">
              <text>{{ info.commonName }}</text>
              <!-- <text>滹沱河艺术生态岛</text> -->
            </view>
          </view>
          <view class="ticket-cards">
            <view
              class="ticket-card"
              v-for="it in info.detaildVoList || []"
              :key="it.orderDetailsId"
            >
              <view class="top">
                <view class="ticket-name">{{ it.typeName }}</view>
                <!-- <view class="ticket-name">成人票</view> -->
                <view class="ticket-num">x {{ it.ticketCount }}</view>
                <!-- <view class="ticket-num">x 1</view> -->
              </view>
              <view class="bottom">
                <!-- <view class="ticket-validity"
                  >预约日期 {{ it.ticketDate }}</view
                > -->
                <view class="ticket-validity">预约日期</view>
                <view class="date"> {{ it.ticketDate }}</view>
              </view>
              <view class="bottom" v-if="info.orderTname">
                <view class="ticket-validity">游客姓名</view>
                <!-- <view class="date"> 方淑华</view> -->
                <view class="ticket-validity">{{ info.orderTname }}</view>
                <!--              <view class="date">{{ info.typeName }}</view>-->
              </view>
              <view class="bottom" v-if="info.orderTphone">
                <view class="ticket-validity">联系电话</view>
                <view class="date"> {{ info.orderTphone }} </view>
                <!-- <view class="date"> 13331371679 </view> -->
              </view>
              <view class="bottom" v-if="info.orderTcode">
                <view class="ticket-validity">证件号码</view>
                <view class="label-text"> {{ info.orderTcode }} </view>
                <!-- <view class="date"> 133333333333 </view> -->
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>

    <!--  按钮      -->
    <view class="btns">
      <block>
        <view class="btn primary w422" @click.stop="handleTicket(id)"
          >确认核销</view
        >
      </block>
    </view>
  </view>
</template>

<script>
import tkiQrcode from "tki-qrcode";

import {
  editAvatar,
  getActiveOrderDetail,
  loginOut,
  ticCheckStatus,
} from "@/config/api";

export default {
  components: {
    tkiQrcode,
  },
  props: ["id"],
  data() {
    return {
      img_baseUrl: process.env.VUE_APP_BASEURL_IMG_API,
      headerClassName: "headerClassBg",
      info: {},
    };
  },
  onLoad() {
    if (this.id) {
      this.getDetail();
    }
  },
  methods: {
    handleTicket() {
      ticCheckStatus({
        _id: this.id,
      })
        .then((check) => {
          uni.showModal({
            title: "提示",
            content:
              check.code == 200
                ? "核销成功，是否继续核销？"
                : "核销异常，是否重试？",
            showCancel: true,
            cancelText: "不了",
            confirmText: check.code == 200 ? "继续核销" : "重新核销",
            success: function (res) {
              if (res.confirm) {
                uni.navigateBack();
              } else if (res.cancel) {
                console.log("用户点击取消");
                uni.navigateBack();
              }
            },
          });
        })
        .catch((err) => {
          uni.showToast({
            icon: "none",
            title: err,
          });
          uni.navigateBack();
        });
    },
    getDetail() {
      getActiveOrderDetail({
        orderNum: this.id,
      }).then((res) => {
        if (res.code === 200) {
          const detail = res.data || {};
          detail.commonName = detail.detaildVoList[0]?.commonName;
          detail.commonPic = detail.detaildVoList[0]?.commonPic;
          this.info = detail;
          if (detail.orderStatus == 4) {
            uni.showModal({
              title: "提示",
              content: "该订单已核销！",
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  console.log("用户点击确定");
                  uni.navigateBack();
                } else if (res.cancel) {
                  console.log("用户点击取消");
                  uni.navigateBack();
                }
              },
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss">
.ticket-detail-page {
  box-sizing: border-box;
  min-height: 100vh;
  background-color: #f7f9fa;

  .wrap {
    min-height: 100vh;
    box-sizing: border-box;
    padding: 0 0 200rpx;
    background: #fff;
    // background: linear-gradient(
    //   180deg,
    //   #c1ddff 0%,
    //   rgba(193, 221, 255, 0) 600rpx,
    //   #f7f9fa 100%
    // );
  }

  .statue-title {
    font-size: 40rpx;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.8);
    line-height: 56rpx;
    margin-bottom: 40rpx;
  }

  .ticket-item {
    background: #ffffff;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    padding: 32rpx;

    .ticket-title {
      display: flex;
      align-items: center;

      .title {
        flex: 1;
        margin-top: 32rpx;
        margin-right: 24rpx;
        display: flex;
        align-items: center;

        image {
          display: block;
          width: 40rpx;
          height: 40rpx;
          margin-right: 16rpx;
          border-radius: 50%;
        }

        text {
          font-size: 28rpx;
          font-weight: 400;
          color: #2187ff;
          line-height: 40rpx;
        }
      }

      .status {
        font-size: 28rpx;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.8);
        line-height: 40rpx;

        &_0 {
          color: #ff7614;
        }

        &_2 {
          color: rgba(0, 0, 0, 0.5);
        }
      }
    }

    .ticket-card {
      margin-top: 48rpx;
      padding: 24rpx;
      box-sizing: border-box;
      min-height: 182rpx;
      background: #f7f9fa;
      border-radius: 16rpx 16rpx 16rpx 16rpx;

      .top {
        display: flex;
        justify-content: space-between;

        .ticket-name {
          font-size: 32rpx;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.8);
          line-height: 44rpx;
        }

        .ticket-price {
          font-size: 32rpx;
          font-family: D-DIN-Bold, D-DIN;
          font-weight: 700;
          color: rgba(0, 0, 0, 0.8);
          line-height: 34rpx;
        }
      }

      .bottom {
        margin-top: 64rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .ticket-validity {
          font-size: 28rpx;
          font-weight: 400;
          color: #777f8f;
          line-height: 40rpx;
        }

        .date {
          font-size: 28rpx;
          font-weight: 700;
          color: rgba(0, 0, 0, 0.7);
          line-height: 40rpx;
        }

        .ticket-num {
          font-size: 32rpx;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.7);
          line-height: 44rpx;
        }
      }
    }
  }

  .pay {
    position: relative;
    margin-top: 36rpx;
    text-align: right;
    font-size: 28rpx;
    font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.7);
    line-height: 40rpx;

    text {
      font-size: 32rpx;
      font-family: D-DIN-Bold, D-DIN;
      font-weight: 700;
      color: #ff7614;
      line-height: 34rpx;
    }
  }

  .order-info-tip {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    font-size: 28rpx;
    font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.5);
    line-height: 40rpx;

    image {
      width: 32rpx;
      height: 32rpx;
      display: block;
      margin-left: 8rpx;
    }
  }

  .card-code {
    margin-top: 24rpx;
    background: #ffffff;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    padding: 60rpx;
    text-align: center;

    .tip {
      font-size: 32rpx;
      font-family: Alibaba PuHuiTi 2-75 SemiBold, Alibaba PuHuiTi 20;
      font-weight: 700;
      color: #3d3d3d;
      line-height: 44rpx;
    }

    .qr-code {
      margin: 24rpx auto 0;
      width: 300rpx;
      height: 300rpx;
      background: #ffffff;
    }
  }

  .card-info {
    margin-top: 32rpx;
  }

  .mt24 {
    margin-top: 24rpx;
  }

  .card-info-title {
    font-size: 32rpx;
    font-weight: 700;
    color: #3d3d3d;
    line-height: 44rpx;
  }

  .info-item {
    margin-top: 24rpx;
    background: #ffffff;
    padding: 32rpx 24rpx;
    border-radius: 24rpx 24rpx 24rpx 24rpx;

    .name {
      display: flex;
      align-items: center;
      font-size: 32rpx;
      font-weight: 400;
      color: rgba(0, 0, 0, 0.8);
      line-height: 44rpx;
    }

    .tag {
      margin-left: 10rpx;
      font-size: 24rpx;
      font-family: Alibaba PuHuiTi 2-45 Light, Alibaba PuHuiTi 20;
      font-weight: 300;
      color: #2187ff;
      line-height: 32rpx;
      background: rgba(77, 134, 247, 0.102);
      border-radius: 8rpx 8rpx 8rpx 8rpx;
      padding: 0 8rpx;
    }

    .p {
      display: flex;
      align-items: center;

      .label {
        margin-right: 48rpx;
        font-size: 28rpx;
        font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
        font-weight: 400;
        color: #777f8f;
        line-height: 40rpx;
      }

      .label-text {
        flex: 1;
        font-size: 28rpx;
        font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.8);
        line-height: 40rpx;
      }
    }
  }

  .btns {
    position: fixed;
    bottom: 0;
    width: calc(100% - 64rpx);
    left: 0;
    height: 124rpx;
    box-sizing: content-box;
    background: #ffffff;
    border-top: 2rpx solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    padding: 16rpx 32rpx calc(env(safe-area-inset-bottom) + 20rpx);

    .btn {
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      padding: 0 28rpx;
      height: 88rpx;
      border: 0;
      font-size: 28rpx;
      font-weight: 400;
      border-radius: 100px;

      &.outline {
        border: 2rpx solid #b7c1ca;
        color: #777f8f;
      }

      &.icon-service {
        image {
          display: block;
          width: 34rpx;
          height: 34rpx;
          margin-right: 14rpx;
        }
      }

      &.w422 {
        width: 422rpx;
      }

      &.w240 {
        width: 240rpx;
      }

      &.primary {
        width: 100%;
        background: #FF5000;
        border: 2rpx solid #FF5000;
        color: #fff;
      }
    }
  }

  .popup-content {
    background: #f7f9fa;
    padding: 32rpx;

    .title {
      position: relative;
      font-size: 32rpx;
      font-family: Alibaba PuHuiTi 2-75 SemiBold, Alibaba PuHuiTi 20;
      font-weight: 700;
      color: #3d3d3d;
      line-height: 44rpx;
      text-align: center;

      image {
        position: absolute;
        right: 0;
        top: 0;
        z-index: 1;
        display: block;
        width: 48rpx;
        height: 48rpx;
        cursor: pointer;
      }
    }
  }
}
</style>
